]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
tests/shell: Fix remaining ESlint errors
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 13 Jul 2023 19:29:13 +0000 (21:29 +0200)
committerEvan Welsh <contact@evanwelsh.com>
Sat, 15 Jul 2023 02:35:56 +0000 (02:35 +0000)
All tests are currently excluded from linting, so errors can sneak
in more easily.

We should change that, so quickly fix up any remaining errors.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2822>

.eslintrc.yml
lint/eslintrc-shell.yml
tests/shell/basic.js
tests/shell/core.js
tests/shell/hwtest.js

index 9289caa258080dcc2f8004a13083feb36378bf29..95be3a07cbfaff7cdefa0f66b5227a5f34658064 100644 (file)
@@ -8,5 +8,6 @@ overrides:
       - js/portalHelper/**
       - subprojects/extensions-app/**
       - subprojects/extensions-tool/**
+      - tests/shell/**
     parserOptions:
       sourceType: module
index e4bf009bcae971201f52389c84e5ffcff775007a..da9c26af1f9939d156ab4e77dbc7f1a166249a15 100644 (file)
@@ -16,7 +16,9 @@ rules:
   jsdoc/require-param-description: off
 
 overrides:
-  - files: js/**
+  - files:
+      - js/**
+      - tests/shell/**
     excludedFiles:
       - js/portalHelper/*
       - js/misc/extensionUtils.js
index 588123fd887561043a27994b5141afc349b2d9de..04c3f87112f2b66b2ba4dcccc72c0908fd0c332f 100644 (file)
@@ -11,6 +11,7 @@ const Scripting = imports.ui.scripting;
 
 export var METRICS = {};
 
+/** @returns {void} */
 export async function run() {
     console.debug('Running basic perf test');
 
@@ -38,7 +39,7 @@ export async function run() {
     Main.panel.statusArea.quickSettings.menu.open();
     await Scripting.sleep(400);
 
-    const { menuManager } = Main.panel;
+    const {menuManager} = Main.panel;
     while (menuManager.activeMenu &&
         Main.panel.navigate_focus(menuManager.activeMenu.sourceActor,
             St.DirectionType.TAB_BACKWARD, false))
@@ -118,26 +119,32 @@ let notificationClosed = false;
 let windowPickerShown = false;
 let appPickerShown = false;
 
+/** @returns {void} */
 export function script_topBarNavDone() {
     topBarNav = true;
 }
 
+/** @returns {void} */
 export function script_notificationShowDone() {
     notificationShown = true;
 }
 
+/** @returns {void} */
 export function script_notificationCloseDone() {
     notificationClosed = true;
 }
 
+/** @returns {void} */
 export function script_overviewShowDone() {
     windowPickerShown = true;
 }
 
+/** @returns {void} */
 export function script_applicationsShowDone() {
     appPickerShown = true;
 }
 
+/** @returns {void} */
 export function finish() {
     if (!topBarNav)
         throw new Error('Failed to navigate top bar');
index 9339601049bb33358b46ffad44f46d28af3bef28..12d9cb060d423f00f86cda4ce526d95b4bee0bf7 100644 (file)
@@ -93,13 +93,14 @@ const WINDOW_CONFIGS = [{
     alpha: true,  maximized: false, count: 10, metric: 'overviewFps10Alpha',
 }];
 
+/** @returns {void} */
 export async function run() {
     /* eslint-disable no-await-in-loop */
-    Scripting.defineScriptEvent("overviewShowStart", "Starting to show the overview");
-    Scripting.defineScriptEvent("overviewShowDone", "Overview finished showing");
-    Scripting.defineScriptEvent("afterShowHide", "After a show/hide cycle for the overview");
-    Scripting.defineScriptEvent("applicationsShowStart", "Starting to switch to applications view");
-    Scripting.defineScriptEvent("applicationsShowDone", "Done switching to applications view");
+    Scripting.defineScriptEvent('overviewShowStart', 'Starting to show the overview');
+    Scripting.defineScriptEvent('overviewShowDone', 'Overview finished showing');
+    Scripting.defineScriptEvent('afterShowHide', 'After a show/hide cycle for the overview');
+    Scripting.defineScriptEvent('applicationsShowStart', 'Starting to switch to applications view');
+    Scripting.defineScriptEvent('applicationsShowDone', 'Done switching to applications view');
 
     // Enable recording of timestamps for different points in the frame cycle
     global.frame_timestamps = true;
@@ -114,7 +115,7 @@ export async function run() {
         // We go to the overview twice for each configuration; the first time
         // to calculate the mipmaps for the windows, the second time to get
         // a clean set of numbers.
-        if ((i % 2) == 0) {
+        if ((i % 2) === 0) {
             let config = WINDOW_CONFIGS[i / 2];
             await Scripting.destroyTestWindows();
 
@@ -175,6 +176,10 @@ let haveSwapComplete = false;
 let applicationsShowStart;
 let applicationsShowCount = 0;
 
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 export function script_overviewShowStart(time) {
     showingOverview = true;
     finishedShowingOverview = false;
@@ -182,6 +187,10 @@ export function script_overviewShowStart(time) {
     overviewFrames = 0;
 }
 
+/**
+ * @param {number} _time - event timestamp
+ * @returns {void}
+ */
 export function script_overviewShowDone(_time) {
     // We've set up the state at the end of the zoom out, but we
     // need to wait for one more frame to paint before we count
@@ -189,32 +198,55 @@ export function script_overviewShowDone(_time) {
     finishedShowingOverview = true;
 }
 
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 export function script_applicationsShowStart(time) {
     applicationsShowStart = time;
 }
 
+/** @returns {void} */
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 export function script_applicationsShowDone(time) {
     applicationsShowCount++;
-    if (applicationsShowCount == 1)
+    if (applicationsShowCount === 1)
         METRICS.applicationsShowTimeFirst.value = time - applicationsShowStart;
     else
         METRICS.applicationsShowTimeSubsequent.value = time - applicationsShowStart;
 }
 
+/** @returns {void} */
+/**
+ * @param {number} _time - event timestamp
+ * @returns {void}
+ */
 export function script_afterShowHide(_time) {
-    if (overviewShowCount == 1)
+    if (overviewShowCount === 1)
         METRICS.usedAfterOverview.value = mallocUsedSize;
     else
         METRICS.leakedAfterOverview.value = mallocUsedSize - METRICS.usedAfterOverview.value;
 }
 
+/**
+ * @param {number} time - event timestamp
+ * @param {number} bytes - event data
+ * @returns {void}
+ */
 export function malloc_usedSize(time, bytes) {
     mallocUsedSize = bytes;
 }
 
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 function _frameDone(time) {
     if (showingOverview) {
-        if (overviewFrames == 0)
+        if (overviewFrames === 0)
             overviewLatency = time - overviewShowStart;
 
         overviewFrames++;
@@ -231,28 +263,37 @@ function _frameDone(time) {
         // be 1 frame for a FPS computation, hence the '- 1'
         let fps = (overviewFrames - 1) / dt;
 
-        if (overviewShowCount == 1) {
+        if (overviewShowCount === 1) {
             METRICS.overviewLatencyFirst.value = overviewLatency;
             METRICS.overviewFpsFirst.value = fps;
-        } else if (overviewShowCount == 2) {
+        } else if (overviewShowCount === 2) {
             METRICS.overviewLatencySubsequent.value = overviewLatency;
         }
 
         // Other than overviewFpsFirst, we collect FPS metrics the second
         // we show each window configuration. overviewShowCount is 1,2,3...
-        if (overviewShowCount % 2 == 0) {
+        if (overviewShowCount % 2 === 0) {
             let config = WINDOW_CONFIGS[(overviewShowCount / 2) - 1];
             METRICS[config.metric].value = fps;
         }
     }
 }
 
+/**
+ * @param {number} time - event timestamp
+ * @param {number} swapTime - event data
+ * @returns {void}
+ */
 export function glx_swapComplete(time, swapTime) {
     haveSwapComplete = true;
 
     _frameDone(swapTime);
 }
 
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 export function clutter_stagePaintDone(time) {
     // If we aren't receiving GLXBufferSwapComplete events, then we approximate
     // the time the user sees a frame with the time we finished doing drawing
index 5d9bfdb54d026ffa068db5edf2a904d9e3b57221..6e72676149b8a338fbcc57ffc9a1a7e471d75885 100644 (file)
@@ -42,10 +42,14 @@ export var METRICS = {
     },
 };
 
+/**
+ * @param {number} milliseconds - time to wait
+ * @returns {callback}
+ */
 function waitAndDraw(milliseconds) {
     let cb;
 
-    let timeline = new Clutter.Timeline({ duration: milliseconds });
+    let timeline = new Clutter.Timeline({duration: milliseconds});
     timeline.start();
 
     timeline.connect('new-frame', (_timeline, _frame) => {
@@ -61,6 +65,11 @@ function waitAndDraw(milliseconds) {
     return callback => (cb = callback);
 }
 
+/**
+ * @param {object} object - emitter object
+ * @param {string} signal - signal name
+ * @returns {callback}
+ */
 function waitSignal(object, signal) {
     let cb;
 
@@ -73,6 +82,9 @@ function waitSignal(object, signal) {
     return callback => (cb = callback);
 }
 
+/**
+ * @returns {number}
+ */
 function extractBootTimestamp() {
     const sp = Gio.Subprocess.new([
         'journalctl', '-b',
@@ -96,22 +108,23 @@ function extractBootTimestamp() {
     return result;
 }
 
+/** @returns {void} */
 export async function run() {
     /* eslint-disable no-await-in-loop */
-    Scripting.defineScriptEvent("desktopShown", "Finished initial animation");
-    Scripting.defineScriptEvent("overviewShowStart", "Starting to show the overview");
-    Scripting.defineScriptEvent("overviewShowDone", "Overview finished showing");
-    Scripting.defineScriptEvent("applicationsShowStart", "Starting to switch to applications view");
-    Scripting.defineScriptEvent("applicationsShowDone", "Done switching to applications view");
-    Scripting.defineScriptEvent("mainViewDrawStart", "Drawing main view");
-    Scripting.defineScriptEvent("mainViewDrawDone", "Ending timing main view drawing");
-    Scripting.defineScriptEvent("overviewDrawStart", "Drawing overview");
-    Scripting.defineScriptEvent("overviewDrawDone", "Ending timing overview drawing");
-    Scripting.defineScriptEvent("redrawTestStart", "Drawing application window");
-    Scripting.defineScriptEvent("redrawTestDone", "Ending timing application window drawing");
-    Scripting.defineScriptEvent("collectTimings", "Accumulate frame timings from redraw tests");
-    Scripting.defineScriptEvent("geditLaunch", "gedit application launch");
-    Scripting.defineScriptEvent("geditFirstFrame", "first frame of gedit window drawn");
+    Scripting.defineScriptEvent('desktopShown', 'Finished initial animation');
+    Scripting.defineScriptEvent('overviewShowStart', 'Starting to show the overview');
+    Scripting.defineScriptEvent('overviewShowDone', 'Overview finished showing');
+    Scripting.defineScriptEvent('applicationsShowStart', 'Starting to switch to applications view');
+    Scripting.defineScriptEvent('applicationsShowDone', 'Done switching to applications view');
+    Scripting.defineScriptEvent('mainViewDrawStart', 'Drawing main view');
+    Scripting.defineScriptEvent('mainViewDrawDone', 'Ending timing main view drawing');
+    Scripting.defineScriptEvent('overviewDrawStart', 'Drawing overview');
+    Scripting.defineScriptEvent('overviewDrawDone', 'Ending timing overview drawing');
+    Scripting.defineScriptEvent('redrawTestStart', 'Drawing application window');
+    Scripting.defineScriptEvent('redrawTestDone', 'Ending timing application window drawing');
+    Scripting.defineScriptEvent('collectTimings', 'Accumulate frame timings from redraw tests');
+    Scripting.defineScriptEvent('geditLaunch', 'gedit application launch');
+    Scripting.defineScriptEvent('geditFirstFrame', 'first frame of gedit window drawn');
 
     await Scripting.waitLeisure();
     Scripting.scriptEvent('desktopShown');
@@ -148,7 +161,7 @@ export async function run() {
     global.frame_finish_timestamp = true;
 
     for (let k = 0; k < 5; k++)
-        await Scripting.createTestWindow({ maximized: true });
+        await Scripting.createTestWindow({maximized: true});
     await Scripting.waitTestWindows();
 
     await Scripting.sleep(1000);
@@ -201,7 +214,7 @@ export async function run() {
     if (windows.length > 0)
         throw new Error('gedit was already running');
 
-    while (windows.length == 0) {
+    while (windows.length === 0) {
         await waitSignal(global.display, 'window-created');
         windows = app.get_windows();
     }
@@ -227,51 +240,99 @@ let redrawTiming;
 let redrawTimes = {};
 let geditLaunchTime;
 
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 export function script_desktopShown(time) {
     let bootTimestamp = extractBootTimestamp();
     METRICS.timeToDesktop.value = time - bootTimestamp;
 }
 
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 export function script_overviewShowStart(time) {
     overviewShowStart = time;
 }
 
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 export function script_overviewShowDone(time) {
     METRICS.overviewShowTime.value = time - overviewShowStart;
 }
 
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 export function script_applicationsShowStart(time) {
     applicationsShowStart = time;
 }
 
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 export function script_applicationsShowDone(time) {
     METRICS.applicationsShowTime.value = time - applicationsShowStart;
 }
 
+/**
+ * @param {number} _time - event timestamp
+ * @returns {void}
+ */
 export function script_mainViewDrawStart(_time) {
     redrawTiming = 'mainView';
 }
 
+/**
+ * @param {number} _time - event timestamp
+ * @returns {void}
+ */
 export function script_mainViewDrawDone(_time) {
     redrawTiming = null;
 }
 
+/**
+ * @param {number} _time - event timestamp
+ * @returns {void}
+ */
 export function script_overviewDrawStart(_time) {
     redrawTiming = 'overview';
 }
 
+/**
+ * @param {number} _time - event timestamp
+ * @returns {void}
+ */
 export function script_overviewDrawDone(_time) {
     redrawTiming = null;
 }
 
+/**
+ * @param {number} _time - event timestamp
+ * @returns {void}
+ */
 export function script_redrawTestStart(_time) {
     redrawTiming = 'application';
 }
 
+/**
+ * @param {number} _time - event timestamp
+ * @returns {void}
+ */
 export function script_redrawTestDone(_time) {
     redrawTiming = null;
 }
 
+/**
+ * @param {number} _time - event timestamp
+ * @returns {void}
+ */
 export function script_collectTimings(_time) {
     for (let timing in redrawTimes) {
         let times = redrawTimes[timing];
@@ -280,9 +341,9 @@ export function script_collectTimings(_time) {
         let len = times.length;
         let median;
 
-        if (len == 0)
+        if (len === 0)
             median = -1;
-        else if (len % 2 == 1)
+        else if (len % 2 === 1)
             median = times[(len - 1) / 2];
         else
             median = Math.round((times[len / 2 - 1] + times[len / 2]) / 2);
@@ -291,18 +352,34 @@ export function script_collectTimings(_time) {
     }
 }
 
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 export function script_geditLaunch(time) {
     geditLaunchTime = time;
 }
 
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 export function script_geditFirstFrame(time) {
     METRICS.geditStartTime.value = time - geditLaunchTime;
 }
 
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 export function clutter_stagePaintStart(time) {
     stagePaintStart = time;
 }
 
+/**
+ * @param {number} time - event timestamp
+ * @returns {void}
+ */
 export function clutter_paintCompletedTimestamp(time) {
     if (redrawTiming != null && stagePaintStart != null) {
         if (!(redrawTiming in redrawTimes))